package com.xu.system.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xu.system.mapper.SysUserMapper;
import com.xu.system.model.entity.SysUser;
import com.xu.system.service.db.ISysUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author 许乾伟
 * @since 2024-12-03 03:53:30
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Override
    public Map<Long, String> getUserNameMap(List<Long> userIds) {
        if (CollectionUtils.isEmpty(userIds)){
            return new HashMap<>();
        }
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.eq(SysUser.IS_DELETE, Boolean.FALSE);
        wrapper.in(SysUser.ID,userIds);
        return list(wrapper).stream().collect(Collectors.toMap(SysUser::getId,SysUser::getUserName));
    }

    @Override
    public List<SysUser> getUserListByIds(List<Long> userIds) {
        if (CollectionUtils.isEmpty(userIds)){
            return new ArrayList<>();
        }
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        wrapper.eq(SysUser.IS_DELETE, Boolean.FALSE);
        wrapper.in(SysUser.ID,userIds);
        return list(wrapper);
    }
}
